class BaseModel<T> {
  int? code;
  int? total;
  String? msg; // 原始消息字段
  T? data;
  T? rows;


  BaseModel({this.code, this.total, this.data, this.msg, this.rows});

  BaseModel.fromJson(Map<String, dynamic> json) {
    code = json["code"];
    total = json["total"];
    data = json["data"];
    msg = json["msg"]; // 保存原始完整消息
    rows = json["rows"];
  }

  // 获取限制长度的消息（最多10个字符）
  String? get getMsg {
    if (msg == null) return null;
    if (msg!.length <= 10) return msg;
    return "${msg!.substring(0, 15)}...";
  }


  Map<String, dynamic> toJson() {
    final Map<String, dynamic> map = <String, dynamic>{};
    map["code"] = code;
    map["total"] = total;
    map["data"] = data;
    map["msg"] = msg; // 仍然使用原始完整消息进行序列化
    map["rows"] = rows;
    return map;
  }
}
